local m = require('utils.vim')
local misc = require('utils.misc')
local helper = require('helper.telescope')
local t = require('helper.textobjects')

m.map('n', ',i', '"_ciw', { noremap = true, silent = true, desc="delete word under cusor and enter insert mode(avoid copied text to default register)" })
m.map('n', ',I', '"_ci"', { noremap = true, silent = true, desc="Delete all content inside double quotes and enter insert mode(avoid copied text to default register)" })

m.map("n", ",y", function()
    m.cmd("normal! yiw")
end,{desc="yank word under cursor"})
m.map("n", ",Y", function()
    if misc.is_cursor_after('"') then
        m.cmd('normal! yi"')
        return
    end
    if misc.is_cursor_after("'") then
        m.cmd("normal! yi'")
        return
    end
    if misc.is_cursor_after("(") then
        m.cmd("normal! yi(")
        return
    end
    if misc.is_cursor_after("{") then
        m.cmd("normal! yi{")
        return
    end
    require('notify')("Not inside quotes defined")
end,{desc="Copy all content inside the paired symbol where the cursor is located (the cursor must be positioned one character before the paired symbol)."})

m.map("n", ",D", function()
    m.cmd("normal! kdd")
end,{desc="delete above line"})
m.map("n", ",d", function()
    m.cmd("normal! jdd")
end,{desc="delete below line"})

m.map("n", ",v", function()
    m.cmd("normal! viw")
end,{desc="select word under cursor"})
m.map("n", ",V", function()
    if misc.is_cursor_after('"') then
        m.cmd('normal! vi"')
        return
    end
    if misc.is_cursor_after("'") then
        m.cmd("normal! vi'")
        return
    end
    if misc.is_cursor_after("(") then
        m.cmd("normal! vi(")
        return
    end
    if misc.is_cursor_after("{") then
        m.cmd("normal! vi{")
        return
    end
    require('notify')("Not inside quotes defined")
end,{desc="Select all content inside the paired symbol where the cursor is located (the cursor must be positioned one character before the paired symbol)."})
m.map("n", "<M-v>", function()
    m.cmd("normal! viw")
    helper.pick_live_grep(true)
end,{desc="select word under cursor and live grep"})

m.map("n", "<M-y>", function()
    local current_line = vim.fn.getline('.')

    done = t.send_key(current_line, "y")
    if done then
        return
    end

    m.cmd("normal! V$%y")
end,{desc="Yank the current code block to clipboard"})

m.map("n", "<M-x>", function()
    local current_line = vim.fn.getline('.')

    done = t.send_key(current_line, "x")
    if done then
        return
    end

    vim.cmd("normal! \"*yy")  -- Yank (copy) the current line to clipboard
    vim.cmd("normal! dd")     -- Delete the current line
end,{desc="Cut the current code block and copy to clipboard"})
-- EOP
